package com.ft.f_springboot_route.controller;


import com.ft.f_springboot_route.bean.Route_Img;
import com.ft.f_springboot_route.service.Route_ImgService;
import com.ft.f_springboot_route.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/Route_Img")
public class Route_ImgController {

    @Autowired
    Route_ImgService Route_ImgService;

    /**
     * 查询方法
     * @param Model
     * @param currentPage
     * @param Route_Id
     * @return
     */
    @RequestMapping("/toRoute_Imglist")
    public String list(Model Model, Integer currentPage, Integer Route_Id, HttpSession HttpSession){
        if (Route_Id == null){
            System.out.println("na");
            System.out.println(HttpSession.getAttribute("RouteId").toString());
            Route_Id = Integer.parseInt(HttpSession.getAttribute("RouteId").toString());
        }else {
            System.out.println("fang");
        HttpSession.setAttribute("RouteId",Route_Id);
        }
        System.out.println(Route_Id);
        Pager<Route_Img> route_imgPager = Route_ImgService.selectlistRoute_Img(Route_Id, currentPage);
        Model.addAttribute("route_imgPager",route_imgPager);
        return "route_img/list";
    }

    /**
     * 修改回显
     * @param Img_Id
     * @param RouteId
     * @param Model
     * @return
     */
    @RequestMapping("/edit")
    public String deit(Integer Img_Id,Integer RouteId,Model Model){
        System.out.println(Img_Id);
        System.out.println(RouteId);
        Route_Img route_img = Route_ImgService.selectRoute_Img(Img_Id);
        Model.addAttribute("route_img",route_img);
        return "route_img/edit";
    }

    /**
     * 修改
     * @param img
     * @param Route_Img
     * @return
     */
    @RequestMapping("/editRoute_Img")
    public String deit(MultipartFile img,Route_Img Route_Img){
        Route_ImgService.edit(img,Route_Img);
        return "redirect:/Route_Img/toRoute_Imglist" + "?Route_Id=" + Route_Img.getRouteId();
    }


    /**
     * 删除
     * @param Img_Id
     * @param RouteId
     * @return
     */
    @RequestMapping("/deleteRoute_Img")
    public String dele(Integer Img_Id,Integer RouteId){
        Route_ImgService.dele(Img_Id);
        return "redirect:/Route_Img/toRoute_Imglist" + "?Route_Id=" + RouteId;
    }

    /**
     * 添加跳转
     * @return
     */
    @RequestMapping("/addtianjia")
    public String addtransfer(HttpSession HttpSession,Model Model){
        Model.addAttribute("RouteId",HttpSession.getAttribute("RouteId"));
        return "route_img/add";
    }

    /**
     * 添加
     * @param Route_Img
     * @param img
     * @return
     */
    @RequestMapping("/add")
    public String add(Route_Img  Route_Img,MultipartFile img){
        System.out.println(Route_Img.toString());
        Route_ImgService.addRoute_Img(Route_Img,img);
        return "redirect:/Route_Img/toRoute_Imglist" + "?Route_Id=" + Route_Img.getRouteId();
    }


}
